define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

		$scope.form.father_id=params.father_id;
		$scope.form.fk_unit='self';
		//查询主校区和分校区
		httpService.post(app.urls.unit_grade_select,{"id":params.id},function(data){
			if("0000" === data.code){
				$scope.grade = data.data[0];
			}else{
				alert(data.msg);
			}
		});
		//查询主校区和分校区
		httpService.post(app.urls.unit_selectSchoolAndAttach,{},function(data){
			if("0000" === data.code){
				$scope.unitList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//查询年级
		httpService.post(app.urls.grade_selectSchoolGrade,{},function(data){
			if("0000" === data.code){
				$scope.gradeList = data.data;
			}else{
				alert(data.msg);
			}
		});
		$scope.saveForm = function(){
			if(!$scope.formCheck()) {
				return;
			}
			httpService.post(app.urls.unit_grade_select,{"fk_unit":$scope.grade.fk_unit,"fk_grade":$scope.grade.fk_grade},function(data){
				if("0000" === data.code){
					if(data.data.length<=0){
						httpService.post(app.urls.unit_grade_update,$scope.grade,function(data){
							if("0000" === data.code){
								eventBusService.publish("content.page.reload", data);
								eventBusService.publish("modal.page.close", {});
							}else{
								alert(data.msg);
							}
						});
					}else {
						alert("重复添加该年级")
					}
				}else{
					alert(data.msg);
				}
			});
		}

	}}});